﻿package mortal.game.view
{
    import com.gengine.global.*;
    import com.greensock.*;
    import com.greensock.easing.*;
    import com.mui.controls.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.mvc.core.*;

    public class RoleUpgradeView extends View
    {
        private var _bg:GImageBitmap;
        private var _levelNumber:BitmapNumberText;
        private var _t:int;
        private static var _instance:RoleUpgradeView;

        public function RoleUpgradeView()
        {
            this.layer = LayerManager.highestLayer;
            this.mouseEnabled = false;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gImageBitmap(ImagesConst.roleUpgradeViewBg, 0, 0, this);
            this._levelNumber = UIFactory.bitmapNumberText(159, 34, "RoleUpgradeViewNum.png", 18, 30, 0, this, 14, BitmapNumberText.Mid);
            this._levelNumber.text = "0";
            this.addTimer();
            this.configEventListener(MouseEvent.CLICK, this.onMouseClick);
            this.updateNumber();
            this.stageResize();
            TweenMax.to(this, 1, {y:this.y - 60, scaleX:1, scaleY:1, ease:Circ.easeOut});
            return;
        }// end function

        private function onMouseClick(event:MouseEvent) : void
        {
            this.hide();
            return;
        }// end function

        private function addTimer() : void
        {
            this.clearTime();
            this._t = setTimeout(hide, 3000);
            return;
        }// end function

        private function clearTime() : void
        {
            if (this._t)
            {
                clearTimeout(this._t);
                this._t = 0;
            }
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            if (isHide)
            {
                super.show(param1, param2);
            }
            else
            {
                this.addTimer();
                this.updateNumber();
                this.stageResize();
                TweenMax.to(this, 1, {y:this.y - 60, scaleX:1, scaleY:1, ease:Circ.easeOut});
            }
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            x = Global.stage.stageWidth - 654;
            y = Global.stage.stageHeight - 250;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bg.dispose(param1);
            this._bg = null;
            this._levelNumber.dispose(param1);
            this._levelNumber = null;
            this.clearTime();
            return;
        }// end function

        public function updateNumber() : void
        {
            this._levelNumber.text = String(Cache.instance.role.roleEntityInfo.entityInfo.level);
            return;
        }// end function

        public static function get instance() : RoleUpgradeView
        {
            if (!_instance)
            {
                _instance = new RoleUpgradeView;
            }
            return _instance;
        }// end function

    }
}
